// 引入路由组件
// import Home from '@/views/Home';
import Search from '@/views/Search';
import Login from '@/views/Login';
import Register from '@/views/Register';
import Detail from '@/views/Detail';
import AddCartSuccess from '@/views/AddCartSuccess';
import ShopCart from '@/views/ShopCart';
import Trade from '@/views/Trade';
import Pay from '@/views/Pay';
import PaySuccess from '@/views/PaySuccess';
import Center from '@/views/Center';
// 引入二级路由组件
import MyOrder from '@/views/Center/myOrder';
import GroupOrder from '@/views/Center/groupOrder';

/*
当打包构建应用时, JavaScript 包会变得非常大, 影响页面加载
如果我们能把不同路由对应的组件分隔成不同的代码块
然后当路由被访问时才加载对应组件,就更高效了
*/
// 路由配置的信息
export default [
	{
		path: '/home',
		component: () => import('@/views/Home'),
		meta: { show: true },
	},
	{
		path: '/detail/:skuid',
		component: Detail,
		meta: { show: true },
	},
	{
		path: '/trade',
		component: Trade,
		meta: { show: true },
		// 路由独享守卫
		beforeEnter: (to, from, next) => {
			// 去交易页面,必须是从购物车而来
			if (from.path == '/shopcart') {
				next();
			} else {
				// 其它的路由组件而来, 停留在当前
				next(from.path);
			}
		},
	},
	{
		path: '/pay',
		component: Pay,
		meta: { show: true },
		// 路由独享守卫
		beforeEnter: (to, from, next) => {
			if (from.path == '/trade') {
				next();
			} else {
				// 其它的路由组件而来, 停留在当前
				next(from.path);
			}
		},
	},
	{
		path: '/paysuccess',
		component: PaySuccess,
		meta: { show: true },
	},
	{
		path: '/center',
		component: Center,
		meta: { show: true },
		// 二级路由组件
		children: [
			{ path: 'myOrder', component: MyOrder },
			{ path: 'groupOrder', component: GroupOrder },
			{ path: '/center', redirect: '/center/myOrder' },
		],
	},
	{
		path: '/addCartSuccess',
		name: 'addCartSuccess',
		component: AddCartSuccess,
		meta: { show: true },
	},
	{
		path: '/shopCart',
		component: ShopCart,
		meta: { show: true },
	},
	{
		path: '/search/:keyword?',
		name: 'search',
		component: Search,
		meta: { show: true },
	},
	{
		path: '/login',
		component: Login,
		meta: { show: false },
	},
	{
		path: '/register',
		component: Register,
		meta: { show: false },
	},
	// 重定向, 在项目跑起来的时候, 访问 /, 立马让他定向到首页
	{
		path: '*',
		redirect: '/home',
	},
];
